#include "Precomp.h"
#include "PluggableFactory.h"

namespace SGF
{
	PluggableFactory& PluggableFactory::getInstance()
	{
		static PluggableFactory instance;
		return instance;
	}

	void* PluggableFactory::create(const char* name) const
	{
		std::map<std::string,void*(*)()>::const_iterator i=constructors.find(std::string(name));
		if(i==constructors.end())
			return NULL;
		else
			return (*(i->second))();
	}

	void PluggableFactory::registerProduct(const char* name, void*(*constructor)(), const type_info& typeinfo)
	{
		constructors[std::string(name)]=constructor;
		this->typeinfo[&typeinfo]=name;
	}

	PluggableFactory::PluggableFactory()
	{
	}

	void PluggableFactory::getProductList(std::list<std::string> &out) const
	{
		for(std::map<std::string,void*(*)()>::const_iterator i=constructors.begin();i!=constructors.end();++i)
		{
			out.push_back(i->first);
		}
	}
}